package com.bilibili.service.impl;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.bilibili.dto.VideoInfoDto;
import com.bilibili.dto.VideoToJedis;
import com.bilibili.entity.*;
import com.bilibili.entity.Collections;
import com.bilibili.exception.BusinessException;
import com.bilibili.mapper.CollectionMapper;

import com.bilibili.mapper.HistoryMapper;
import com.bilibili.mapper.PersonalMapper;
import com.bilibili.mapper.UserMapper;
import com.bilibili.mapper.VideoMapper;
import com.bilibili.service.VideoService;
import com.bilibili.utils.RedisOperations;
import com.bilibili.vo.CommentVo;
import com.bilibili.vo.PersonalData;
import com.bilibili.vo.VideoUserMsgVo;
import com.bilibili.vo.VideoVo;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

import static com.bilibili.constant.BusinessConstant.*;
import static com.bilibili.constant.BusinessConstant.RANDOM_VIDEOS_SHOW_COUNT;

@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    private VideoMapper videoMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisOperations redisOperations;
    @Autowired
    private PersonalMapper personalMapper;
    @Autowired
    private CollectionMapper collectionMapper;
    @Autowired
    private HistoryMapper historyMapper;
    @Override
    public Boolean addvideoPlayback(Integer videoid,Integer userId) {
        if(Objects.isNull(videoid)){
            throw new BusinessException(HttpStatus.BAD_REQUEST,"参数不能为空");
        }
        Boolean set=null;
        String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
        List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
        for (VideoToJedis item : videoToJedis) {
            if (videoid.equals(item.getVideoid())) {
                item.setVideoPlayback(item.getVideoPlayback()+1);
            }
        }
        History history=new History();
        history.setVideoid(videoid);
        history.setUserId(userId);
        History history1 = historyMapper.historyIsExists(history);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String format = df.format(new Date());
        history.setViewingtime(format);
        Boolean videoExpExists = videoMapper.isVideoExpExists(userId);
        VideoExp videoExp=new VideoExp();
        Date date=new Date();
        videoExp.setVideowatchdate(date);
        videoExp.setCoinfrequency(0);
        videoExp.setUserId(userId);
        if(!videoExpExists){
            Integer integer = videoMapper.addVideoExp(videoExp);
            Personal personal=new Personal();
            personalMapper.addExp(userId,5);
        }else{
            VideoExp videoExpDate = videoMapper.getVideoExpDate(userId);
            Date videowatchdate = videoExpDate.getVideowatchdate();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String format1 = sdf.format(date);
            String format2 = sdf.format(videowatchdate);
            System.out.println(format1);
            System.out.println(format2);
            if(!format1.equals(format2)){
                videoExp.setCoinfrequency(0);
                videoExp.setVideowatchdate(date);
                videoMapper.UpDateVideoExpByDate(videoExp);
                videoMapper.UpDateVideoExpByCoin(videoExp);
                personalMapper.addExp(userId,5);
            }
        }
        if(Objects.isNull(history1)){
          historyMapper.addhistory(history);
        }else{
            historyMapper.updatehistory(history);
        }
        set = redisOperations.set(REDIS_COMPLETE_VIDEO_KEY, videoToJedis);
        return set;
    }

    @Override
    public Boolean addvideo(String videoimgurl, String videourl, Integer userId, Double videotime, String videoname) {
        if (Objects.isNull(videoimgurl) || Objects.isNull(videourl) || Objects.isNull(userId) || Objects.isNull(videotime) || Objects.isNull(videoname)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "参数不能有空的");
        }
        String videotime1 = null;
        int c = (int) (double) videotime;
        if (c > 60) {
            int minute = c / 60;
            int second = c % 60;
            String mintue1 = null;
            String second1 = null;
            if (minute < 10) {
                mintue1 = "" + minute;
            } else {
                mintue1 = minute + "";
            }
            if (second < 10) {
                second1 = "0" + second;
            } else {
                second1 = second + "";
            }
            videotime1 = mintue1 + ":" + second1;
        } else {
            String second1 = null;
            if (c < 10) {
                second1 = "0" + c;
            } else {
                second1 = second1 + "";
            }
            videotime1 = "00:" + second1;
        }
        Video video = new Video();
        video.setVideosrc(videourl);
        video.setImgsrc(videoimgurl);
        video.setUserId(userId);
        video.setVideotime(videotime1);
        video.setVideoname(videoname);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String format = df.format(new Date());
        video.setVideouploadtime(format);
         videoMapper.addVideo(video);
        VideoToJedis videoToJedis=new VideoToJedis();
        videoToJedis.setVideocollection(0);
        videoToJedis.setVideothumbsup(0);
        videoToJedis.setVideobarrages(0);
        videoToJedis.setVideoPlayback(0);
        videoToJedis.setVideocoin(0);
        videoToJedis.setVideoid(video.getId());
      videoMapper.addVideoToRedis(videoToJedis);
        Integer id = videoToJedis.getId();
        System.out.println(id);
        VideoToJedis videoToJedis1 = videoMapper.getvideoToReidsbyid(id);
        String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
       List<VideoToJedis> videoToJedis2= JSON.parseArray(redisToMysql, VideoToJedis.class);
       videoToJedis2.add(videoToJedis1);
      Boolean  set = redisOperations.set(REDIS_COMPLETE_VIDEO_KEY, videoToJedis2);
        return set;
    }

    @Override
    public List<Video> getRandomVideo() {
        List<Integer> ids = new ArrayList<>();

        ids.add(1);
        for (int id : ids) {
            if (Objects.isNull(videoMapper.getVideoById(id))) {
                throw new BusinessException(HttpStatus.BAD_REQUEST, "视频查询失败");
            }
        }
        List<Video> randomVideo = videoMapper.getRandomVideo(ids);
        return randomVideo;
    }

    @Override
    public Video getVideoById(Integer id, Integer userId) {
        if (Objects.isNull(id)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的id不能为空");
        }
        Video videoById = null;
        if (!Objects.isNull(videoMapper.getVideoById(id))) {
            videoById = videoMapper.getVideoById(id);
            VideoFlag videoFlag = new VideoFlag();
            videoFlag.setVideoid(id);
            videoFlag.setUserId(userId);
            Boolean videoByFlagExists = videoMapper.isVideoByFlagExists(videoFlag);
            if (!videoByFlagExists) {
                videoFlag.setVideocoinflag(-1);
                videoFlag.setVideocollectionflag(-1);
                videoFlag.setVideothumbsupflag(-1);
                videoFlag.setVideobarragesflag(-1);
                videoMapper.addVideoByFlag(videoFlag);
            }
        } else {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "视频查询失败");
        }
        return videoById;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
    public void syncRedisCompletequestionToMySql() {
        String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
        List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
        System.out.println(videoToJedis);
        List<Integer> ids = new ArrayList<>();
        for (int i = 0; i < videoToJedis.size(); i++) {
            ids.add(videoToJedis.get(i).getId());
            Integer number = videoMapper.updateVideoToRedisByid(videoToJedis.get(i));
            System.out.println(number);
        }
    }

    @Override
    public Boolean changeThumbsUp(Integer id, Integer changeNumber, Integer userId) {
        boolean set = false;
        if (Objects.isNull(id) || Objects.isNull(changeNumber)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数不能有空值");
        } else {
            String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
            List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
            for (VideoToJedis item : videoToJedis) {
                if (id.equals(item.getVideoid())) {
                    item.setVideothumbsup(item.getVideothumbsup() + changeNumber);
                }
            }
            set = redisOperations.set(REDIS_COMPLETE_VIDEO_KEY, videoToJedis);
            videoMapper.updateVideoByThumbSupFlag(changeNumber, id, userId);
        }
        return set;
    }

    @Override
    public VideoToJedis getVideoToJedisByid(Integer videoid) {
        if (Objects.isNull(videoid)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数不能为空");
        }
        VideoToJedis videobyJedis = new VideoToJedis();
        if (!Objects.isNull(videoid)) {
            String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
            List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
            for (int i = 0; i < videoToJedis.size(); i++) {
                if (videoid.equals(videoToJedis.get(i).getVideoid())) {
                    videobyJedis = videoToJedis.get(i);
                }
            }
        } else {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "Redis查询失败");
        }
        System.out.println(videobyJedis);
        return videobyJedis;
    }


    @Override
    public Boolean changecollection(Integer id, Integer changecollection, Integer userId) {
        System.out.println(changecollection);
        boolean set = false;
        boolean aBoolean = false;
        if (Objects.isNull(id) || Objects.isNull(changecollection)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数不能有空值");
        } else {
            String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
            List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
            for (VideoToJedis item : videoToJedis) {
                if (id.equals(item.getVideoid())) {
                    item.setVideocollection(item.getVideocollection() + changecollection);
                }
            }
            Collections collection=new Collections();
            collection.setUserId(userId);
            collection.setVideoid(id);
            if(changecollection>0){
                Boolean addcollection = collectionMapper.addcollection(collection);
                System.out.println(addcollection);
            }else{
                Boolean delcollection = collectionMapper.delcollection(collection);
                System.out.println(delcollection);
            }
            set = redisOperations.set(REDIS_COMPLETE_VIDEO_KEY, videoToJedis);
            aBoolean = videoMapper.updateVideoCollectionFlag(changecollection, id, userId);
        }
        return set && aBoolean;
    }

    @Override
    public Boolean changecoin(Integer id, Integer changecoin, Integer userId) {
        boolean set = false;
        boolean aBoolean = false;
        System.out.println(id);
        if (Objects.isNull(id) || Objects.isNull(changecoin) || Objects.isNull(userId)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数不能有空值");
        } else {
            VideoFlag videoFlag = new VideoFlag();
            videoFlag.setUserId(userId);
            videoFlag.setVideoid(id);
            VideoFlag videoFlag1 = videoMapper.getVideoFlag(videoFlag);
            if (videoFlag1.getVideocoinflag() != 1) {
                String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);
                List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
                for (VideoToJedis item : videoToJedis) {
                    if (id.equals(item.getVideoid())) {
                        item.setVideocoin(item.getVideocoin() + changecoin);
                    }
                }
                set = redisOperations.set(REDIS_COMPLETE_VIDEO_KEY, videoToJedis);
                aBoolean = videoMapper.updateVideoByVideoCoinFlag(changecoin, id, userId);
                return set & aBoolean;
            } else {
                return true;
            }

        }

    }

    @Override
    public VideoFlag getVideoFlag(Integer id, Integer userId) {
        if (Objects.isNull(id) || Objects.isNull(userId)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入参数不能为空");
        }
        VideoFlag videoFlag = new VideoFlag();
        videoFlag.setVideoid(id);
        videoFlag.setUserId(userId);
        Boolean videoByFlagExists = videoMapper.isVideoByFlagExists(videoFlag);
        if (videoByFlagExists) {
            return videoMapper.getVideoFlag(videoFlag);
        } else {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "数据库中没有视频旗帜");
        }
    }

    @Override
    public Boolean changeUserCoin(Integer userId, Integer coin) {
        Boolean updatecoin=null;
        if(Objects.isNull(userId)||Objects.isNull(coin)){
            throw  new BusinessException(HttpStatus.BAD_REQUEST,"传入的参数不能有空值");
        }else{
            updatecoin = videoMapper.updatecoin(coin, userId);
            VideoExp videoExpDate = videoMapper.getVideoExpDate(userId);
            Integer coinfrequency = videoExpDate.getCoinfrequency();
            MyCoin myCoin=new MyCoin();
            Date date=new Date();
            Timestamp timestamp = new Timestamp(date.getTime());
            myCoin.setDateTime(timestamp);
            myCoin.setChanges("-1");
            myCoin.setReasons("给视频投币");
            myCoin.setUserId(userId);
            userMapper.addCoinRecord(myCoin);
            if(coinfrequency!=5){
              videoExpDate.setCoinfrequency(videoExpDate.getCoinfrequency()+1);
                videoMapper.UpDateVideoExpByCoin(videoExpDate);
                personalMapper.addExp(userId,10);
            }
        }
        return updatecoin ;
    }

    @Override
    public List<CommentVo> getAllComment(Integer id, Integer userId) {
        System.out.println("评论视频id为" + id);
        System.out.println("用户id为" + userId);
        if (Objects.isNull(id)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "输入的视频id有误");
        }
        if (Objects.isNull(videoMapper.getAllCommentByid(id))) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "该视频还没有评论");
        }
        List<Comment> allCommentByid = videoMapper.getAllCommentByid(id);
        System.out.println(allCommentByid);
        List<CommentVo> commentVos = new ArrayList<>();
        for (Comment item : allCommentByid) {
            if (item.getParentid() == 0) {
                CommentVo commentVo = new CommentVo();
                Integer userId1 = item.getUserId();
                commentVo.setCommenttile(item.getCommenttitle());
                PersonalData personalByuserId = personalMapper.getPersonalByuserId(userId1);
                Space spaceByuserId = personalMapper.getSpaceByuserId(userId1);
                commentVo.setId(item.getId());
                commentVo.setUsername(personalByuserId.getName());
                commentVo.setUserimg(personalByuserId.getImage());
                commentVo.setFans(spaceByuserId.getFans());
                commentVo.setLevel(personalByuserId.getLevel());
                commentVo.setConcerns(spaceByuserId.getConcerns());
                commentVo.setVideoid(item.getVideoid());
                commentVo.setUserId(userId1);
                commentVo.setParentid(item.getParentid());
                commentVos.add(commentVo);
            }
        }
        /**
         * 获取所有父节点；
         */
        for (CommentVo item1 : commentVos) {
            List<CommentVo> commentVoList = new ArrayList<>();
            for (Comment item : allCommentByid) {
                if (item.getParentid().equals(item1.getId())) {
                    CommentVo commentVo = new CommentVo();
                    Integer userId1 = item.getUserId();
                    commentVo.setCommenttile(item.getCommenttitle());
                    PersonalData personalByuserId = personalMapper.getPersonalByuserId(userId1);
                    Space spaceByuserId = personalMapper.getSpaceByuserId(userId1);
                    commentVo.setId(item.getId());
                    commentVo.setUserimg(personalByuserId.getImage());
                    commentVo.setFans(spaceByuserId.getFans());
                    commentVo.setUsername(personalByuserId.getName());
                    commentVo.setLevel(personalByuserId.getLevel());
                    commentVo.setConcerns(spaceByuserId.getConcerns());
                    commentVo.setVideoid(item.getVideoid());
                    commentVo.setUserId(userId1);
                    commentVo.setParentid(item.getParentid());
                    commentVoList.add(commentVo);
                }
            }
            item1.setChildCommentvos(commentVoList);
        }
        return commentVos;
    }

    @Override
    public Integer sendComment(CommentVo commentVo) {
        if (Objects.isNull(commentVo)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数不能为空");
        }
        Comment comment = new Comment();
        comment.setCommenttitle(commentVo.getCommenttile());
        comment.setVideoid(commentVo.getVideoid());
        comment.setUserId(commentVo.getUserId());
        comment.setParentid(commentVo.getParentid());
        Integer integer = videoMapper.addComment(comment);
        System.out.println(comment);
        if (Objects.isNull(integer)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "数据库插入评论失败");
        }
        return comment.getId();
    }

    @Override
    public VideoUserMsgVo getUserMsgById(Integer userId) {
        if (Objects.isNull(userId)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的参数有误");
        }
        Space spaceByuserId = personalMapper.getSpaceByuserId(userId);
        if (Objects.isNull(spaceByuserId)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "数据库查询异常");
        }
        PersonalData personalByuserId = personalMapper.getPersonalByuserId(userId);
        if (Objects.isNull(personalByuserId)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "数据库查询异常");
        }
        Integer coin = personalByuserId.getCoin();
        Integer concerns = spaceByuserId.getConcerns();
        Integer fans = spaceByuserId.getFans();
        String userImg = personalByuserId.getImage();
        Integer level = personalByuserId.getLevel();
        String name = personalByuserId.getName();
        VideoUserMsgVo videoUserMsgVo = new VideoUserMsgVo();
        videoUserMsgVo.setUserimg(userImg);
        videoUserMsgVo.setCoins(coin);
        videoUserMsgVo.setUsername(name);
        videoUserMsgVo.setConcerns(concerns);
        videoUserMsgVo.setFans(fans);
        videoUserMsgVo.setLevel(level);
        videoUserMsgVo.setId(userId);
        return videoUserMsgVo;
    }

    @Override
    public List<VideoVo> getAllVideo() {
        List<VideoVo> videoVos = new ArrayList<>();
        boolean exists = redisOperations.exists(REDIS_COMPLETE_VIDEO_KEY);
        if (exists) {
            String redisToMysql = redisOperations.get(REDIS_COMPLETE_VIDEO_KEY);

            List<VideoToJedis> videoToJedis = JSON.parseArray(redisToMysql, VideoToJedis.class);
            if (Objects.isNull(videoToJedis)) {
                throw new BusinessException(HttpStatus.BAD_REQUEST, "Redis缓存中没有读取到数据");
            }
            List<Video> allVideo1 = videoMapper.getAllVideo();
            Random random=new Random();
            Integer size=allVideo1.size();
            Set<Video> totals=new HashSet<>();
            List<Video> allVideo=new ArrayList<>();
            while(totals.size()<5){
                totals.add(allVideo1.get(random.nextInt(size)));
            }
            Iterator iterator=totals.iterator();
            while ((iterator.hasNext())){
               Video next=(Video) iterator.next();
               allVideo.add(next);
            }
            System.out.println(allVideo);
            if (Objects.isNull(allVideo)) {
                throw new BusinessException(HttpStatus.BAD_REQUEST, "数据库中没有查到数据");
            }
            for (int index = 0; index < allVideo.size(); index++) {
                VideoVo videoVo = new VideoVo();
                videoVo.setId(allVideo.get(index).getId());
                videoVo.setVideotime(allVideo.get(index).getVideotime());
                String name = personalMapper.getPersonalByuserId(allVideo.get(index).getUserId()).getName();
                videoVo.setUsername(name);
                videoVo.setVideouploadtime(allVideo.get(index).getVideouploadtime());
                videoVo.setVideosrc(allVideo.get(index).getVideosrc());
                videoVo.setImgsrc(allVideo.get(index).getImgsrc());
                videoVo.setVideoname(allVideo.get(index).getVideoname());
                videoVo.setVideocoin(videoToJedis.get(index).getVideocoin());
                videoVo.setVideoPlayback(videoToJedis.get(index).getVideoPlayback());
                videoVo.setVideocollection(videoToJedis.get(index).getVideocollection());
                videoVo.setVideobarrages(videoToJedis.get(index).getVideobarrages());
                videoVo.setVideothumbsup(videoToJedis.get(index).getVideothumbsup());
                videoVo.setUserId(allVideo.get(index).getUserId());
                videoVos.add(videoVo);
            }
        } else {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "Redis里没有缓存");
        }
        return videoVos;
    }

    @Override
    public List<BulletChat> getBulletChatByid(Integer videoid) {
        if (Objects.isNull(videoid)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "传入的id不能为空");
        }
        return videoMapper.getBulletChatByid(videoid);
    }

    @Override
    public Boolean addBulletChat(BulletChat bulletChat) {
        if (Objects.isNull(bulletChat)) {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "插入的弹幕不能为空");
        }
        if (videoMapper.addBulletChat(bulletChat) > 0) {
            return true;
        } else {
            throw new BusinessException(HttpStatus.BAD_REQUEST, "插入弹幕失败");
        }

    }
    @Override
    public List<VideoInfoDto> getNewestVideos() {
        List<VideoInfoDto> newestVideos = videoMapper.getNewestVideos(VIDEO_NEWEST_SHOW_COUNT);
        if (CollectionUtils.isEmpty(newestVideos)) {
            throw new BusinessException(HttpStatus.NOT_FOUND, "不存在视频信息");
        }
        return newestVideos;
    }

    @Override
    public List<Video> getHotestVideos() {
        List<Integer> vids = new ArrayList<>();
        List<VideoToJedis> redisVideos = JSON.parseArray(redisOperations.get(REDIS_COMPLETE_VIDEO_KEY), VideoToJedis.class);
        //排序
        java.util.Collections.sort(redisVideos, (o1, o2) -> o2.getVideoPlayback().compareTo(o1.getVideoPlayback()));
        //取指定数量的排行榜前几名
        redisVideos = redisVideos.subList(HOTEST_RANK_START_OFFSET, HOTEST_VIDEOS_SHOW_COUNT);
        //遍历所有IDb,根据Id获取video对象
        redisVideos.stream().forEach(videoToJedis -> {
            vids.add(videoToJedis.getVideoid());
        });
        List<Video> hotestVideos = videoMapper.getVideosByIds(vids);
        if (CollectionUtils.isEmpty(hotestVideos)) {
            throw new BusinessException(HttpStatus.NOT_FOUND, "不存在视频信息");
        }


        return hotestVideos;
    }

    @Override
    public List<VideoInfoDto> getRandomVideos() {
        //1.获取所有视频列表的id,随机抽取不重复的10个id，再将这10个id从数据库拿去对应信息
        List<Integer> videosIds = videoMapper.getAllVideosIds();
        //打乱
        java.util.Collections.shuffle(videosIds);
        videosIds = videosIds.subList(RANDOM_RANK_START_OFFSET, RANDOM_VIDEOS_SHOW_COUNT);
        List<VideoInfoDto> randomVideos = videoMapper.getVideoInfosByIds(videosIds);
        if (CollectionUtils.isEmpty(randomVideos)) {
            throw new BusinessException(HttpStatus.NOT_FOUND, "不存在视频信息");
        }
        return randomVideos;
    }

}
